package day6.problem3;

import java.util.*;

//高精度乘法
//https://www.nowcoder.com/practice/c4c488d4d40d4c4e9824c3650f7d5571?tpId=196&tqId=37177&ru=/exam/oj

public class Solution {
    public String solve (String s, String t) {
        int n = s.length(), m = t.length();
        s = new StringBuffer(s).reverse().toString();
        t = new StringBuffer(t).reverse().toString();
        int[] num = new int[n + m];
        for(int i = 0; i<n; i++) {
            for(int j = 0; j<m; j++) {
                num[i + j] += (s.charAt(i) - '0') * (t.charAt(j) - '0');
            }
        }
        StringBuffer ret = new StringBuffer();
        int jz = 0;
        int i = 0;
        while(i < n + m) {
            int x = (num[i] + jz) % 10;
            jz = (num[i] + jz) / 10;
            ret.append(x);
            i++;
        }
        while(jz > 0) {
            ret.append((jz % 10));
            jz /= 10;
        }
        while(ret.length() > 1 && ret.charAt(ret.length()-1) == '0') {
            ret.deleteCharAt(ret.length()-1);
        }
        return ret.reverse().toString();
    }
}